<?php

namespace App\Console\Commands;

use App\Model\StoreModel;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use App\Model\UserModel;


class VipDay extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'vipday';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '加vip天数';//够365天就清空天数,而且关闭仓库,降级

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //
//        Log::info('自动打印');
        //判断是否够365天,够365天将天数清0,变为普通会员,仓库关闭
        $users = UserModel::get();
        foreach ($users as $k => $v){
            if($v->vip_day >= 365){
                UserModel::where('id',$v->id)->where('level','>',0)->update(['vip_day'=>0,'level'=> 0]);
                StoreModel::where('uid',$v->id)->update(['is_end'=>2]);
            }else{
                UserModel::where('id',$v->id)->where('level','>',0)->increment('vip_day',1);
            }
        }


    }
}
